package com.kang.service.subject.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kang.bean.bot.Answer;
import com.kang.mapper.AnswerMapper;
import com.kang.service.subject.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: service
 * @description: 答案集服务类
 * @author: K.faWu
 * @create: 2022-04-29 21:56
 **/
@Service
public class AnswerServiceImpl extends ServiceImpl<AnswerMapper, Answer> implements AnswerService {
    @Autowired
    private AnswerMapper answerMapper;


    @Override
    public int addEmoticon(Answer answer) {
        QueryWrapper<Answer> answerQueryWrapper = new QueryWrapper<>();
        answerQueryWrapper.eq("text", answer.getText());
        List<Answer> answers = answerMapper.selectList(answerQueryWrapper);
        if (answers!= null && answers.size()>0){
            //该表情包已拥有
           return -1;
        }
        answerMapper.insert(answer);
        return 1;
    }
}
